<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller {
	public $layout_view = 'layout/login';
	public function index()
	{
		$this->layout->title('Login'); // Set page title
		$this->load->model('User_model', 'user');
		$this->load->helper(array('input', 'url'));
		array_walk($_POST, 'cleanValue');
		if(!empty($_POST)){
			$userInfo = $this->user->auth($_POST);
			if(!empty($userInfo)){
				$this->session->set_userdata(array('admin' => $userInfo));
				$this->session->sess_expiration = 60*60*1;
				redirect(SITE_URL.'/home/index/', 'refresh');
			}
			else{
				$data['msg'] = array('type' => 'alert-danger', 'str' => 'Wrong username or password.');
			}
		}
		$this->layout->view('login_index', $data);// Render view and layout
	}
	public function quit()
	{
		$this->load->helper('url');
		$this->session->unset_userdata('admin');
		redirect(SITE_URL.'/login/index/', 'refresh');
	}
}
